home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / ColorPenState.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-01  |  3.1 KB  |  135 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ColorPenState.c
  3.  
  4.     Contains:    Utility routines to save and restore the graphics state of a grafport.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. #include "ColorPenState.h"
  28. #include "ColorUtils.h"
  29. #include "Assertions.h"
  30.  
  31. //-----------------------------------------------------------------------------------------
  32. //    • GetColorAndPenState
  33. //
  34. //    Gets the current drawing environment and stores the data in state. We copy pen and back
  35. //    pix pats only if they are not type 0 (plain ol expanded black and white patterns).
  36. //-----------------------------------------------------------------------------------------
  37.  
  38. void
  39. GetColorAndPenState( ColorPenState* state )
  40. {
  41.     GrafPtr            curPort;
  42.     
  43.     GetPort( &curPort );
  44.     
  45.     state->pnPixPat = NewPixPat();
  46.     state->bkPixPat = NewPixPat();
  47.  
  48.     GetForeColor( &state->foreColor );
  49.     GetBackColor( &state->backColor );
  50.     
  51.     GetPortPenPixPat( curPort, state->pnPixPat );
  52.     GetPortBackPixPat( curPort, state->bkPixPat );
  53.         
  54.     GetPenState( &state->pen );
  55.     state->textMode = GetPortTextMode( curPort );
  56. }
  57.  
  58. //-----------------------------------------------------------------------------------------
  59. //    • SetColorAndPenState
  60. //
  61. //    Sets the current drawing environment based on the data in state.
  62. //-----------------------------------------------------------------------------------------
  63.  
  64. void
  65. SetColorAndPenState( ColorPenState* state, Boolean dispose )
  66. {
  67.     GrafPtr        curPort;
  68.     
  69.     GetPort( &curPort );
  70.  
  71.     SetPenState( &state->pen );
  72.  
  73.     RGBForeColor( &state->foreColor );
  74.     RGBBackColor( &state->backColor );
  75.  
  76.     if ( state->pnPixPat )
  77.         SetPortPenPixPat( curPort, state->pnPixPat );
  78.     
  79.     if ( state->bkPixPat )
  80.         SetPortBackPixPat( curPort, state->bkPixPat );
  81.  
  82.     TextMode( state->textMode );
  83.     
  84.     if ( dispose )
  85.         DisposeColorAndPenState( state );
  86. }
  87.  
  88. //-----------------------------------------------------------------------------------------
  89. //    • DisposeColorAndPenState
  90. //
  91. //    Blow away any pixpats we might have
  92. //-----------------------------------------------------------------------------------------
  93.  
  94. void
  95. DisposeColorAndPenState( ColorPenState* state )
  96. {
  97.     if ( state->pnPixPat )
  98.     {
  99.         DisposePixPat( state->pnPixPat );
  100.         state->pnPixPat = nil;
  101.     }
  102.  
  103.     if ( state->bkPixPat )
  104.     {
  105.         DisposePixPat( state->bkPixPat );
  106.         state->bkPixPat = nil;
  107.     }
  108. }
  109.  
  110. //-----------------------------------------------------------------------------------------
  111. //    • NormalizeColorAndPen
  112. //
  113. //    Sets up our environment to standard drawing fare.
  114. //-----------------------------------------------------------------------------------------
  115.  
  116. void
  117. NormalizeColorAndPen()
  118. {
  119.     RGBColor        black, white;
  120.     Pattern            whitePat = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  121.     GrafPtr            curPort;
  122.     
  123.     GetPort( &curPort );
  124.     
  125.     black.red = black.green = black.blue = 0x0000;
  126.     white.red = white.green = white.blue = 0xFFFF;
  127.     
  128.     RGBForeColor( &black );
  129.     RGBBackColor( &white );
  130.  
  131.     PenNormal();
  132.     BackPat( &whitePat );
  133.     TextMode( srcOr );
  134. }
  135.